<!DOCTYPE html>
<html>
<head>
	<title><%= title%></title>
	<meta charset="utf-8">
	<link rel="stylesheet" type="text/css" href="../bower_components/bootstrap/dist/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="../styles/main.css">
	<script type="text/javascript" src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
	<script type="text/javascript" src="../bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="../bower_components/kindeditor/kindeditor-min.js"></script>
	<script type="text/javascript" src="../bower_components/kindeditor/lang/zh-CN.js"></script>
	<script type="text/javascript" src="../bower_components/upload-jquery/jquery.upload.js"></script>
	<script type="text/javascript" src="../scripts/main.js"></script>
</head>
<style type="text/css">
	.form-group{
		overflow: hidden;
	}
</style>
<body>
	<div class="container">
		<form action="/admin/addArticle" method="post">
			<div class="rows">
				<div class="col-md-offset-2 col-md-9">
					<div class="page-header">
						添加文章
					</div>
					<%if(error!=""){%>
						<div class="alert alert-danger alert-dismissible"  role="alert">
  						<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<%=error%>
						</div>   
					<%}%>

					
					<div class="form-group">
					    <label>文章标题：</label>
					    <div class="rows">
						    <div class="col-md-11">
						    	<input type="text" class="form-control " placeholder="请输入文章标题" name="title">
						    </div>
						    <div class="col-md-1" style="height: 34px;line-height: 34px;color: red;">
						    	<span>*</span>
						    </div>
					    </div>
					</div>
					<div class="form-group">
					    <label>图片：</label>
					    <div>
					    	<div class="col-md-9">
					    		<div class="bk"  style="background:url() ;"></div>
						    	<input type="hidden" id="img" name="img" class="form-control">
						    </div>
						    <div  class="col-md-2">
						    	<input type="button" class="btn btn-info" onclick="doUpload()" value="点击上传">
						    </div>
						    <div class="col-md-1" style="height: 34px;line-height: 34px;color: red;">
						    	<span>*</span>
						    </div>
					    </div>
					</div>
					<div class="form-group">
					    <label style="display: block;">分类：</label>
					    <div class="col-md-11">
					    	 <select name="cata_id" class="form-control">
					    	 	<option value="$">--- 请选择分类 ---</option>
						    <%for(var i=0;i<catalogs.length;i++){%>
						    	<option value="<%=catalogs[i].id %>"><%=catalogs[i].name %></option>
						    <%}%>
						    </select>
					    </div>
					  	<div class="col-md-1" style="height: 34px;line-height: 34px;color: red;">
					    	<span>*</span>
					    </div>
					</div>
					<div class="form-group">
					    <label>文章内容：</label>
					    <textarea type="text" class="form-control" rows="10" placeholder="请输入文章内容" name="content"></textarea> 
					</div>
					
					<button type="submit" id="submit" class="btn btn-success">提交</button>
					<a class="btn btn-info" href="/admin">返回列表</a>
				</div>
			</div>
		</form>
		
						
						
	<script>
        var editor;
			KindEditor.ready(function(K) {
				editor = K.create('textarea[name="content"]', {
					allowFileManager : true
				});
			})
		function doUpload() {
			// 上传方法
			$.upload({
					// 上传地址
					url: '/admin/uploadfile', 
					// 文件域名字
					fileName: 'fileInput', 
					// 其他表单数据
					params: {},
					// 上传完成后, 返回json, text
					dataType: 'text',
					// 上传之前回调,return true表示可继续上传
					onSend: function() {
							return true;
					},
					// 上传之后回调
					onComplate: function(data) {
						$('#img').val(data)
						// $('#img_prv').attr('src',"/"+data)
						// $('#img_prv').css('display','inline')
						$(".bk").attr("style","background:url(/"+data+") no-repeat center center ;background-size:100% auto;")
					}
			});
		}
		setTimeout(function(){
			$('.alert').fadeOut(3000);
		},3000)
		// $('#submit').click(function(){
		// 	if ($('[name="title"]').val()=="") {
		// 		alert("标题不能为空");
		// 		return false;
		// 	}
		// })
</script>
</body>
</html>